home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / lzhtv10.arc / MINICRT.PAS < prev    next >
Pascal/Delphi Source File  |  1989-04-21  |  8KB  |  343 lines

  1.  
  2. (*
  3.  * Copyright 1987, 1989 Samuel H. Smith;  All rights reserved
  4.  *
  5.  * This is a component of the ProDoor System.
  6.  * Do not distribute modified versions without my permission.
  7.  * Do not remove or alter this notice or any other copyright notice.
  8.  * If you use this in your own program you must distribute source code.
  9.  * Do not use any of this in a commercial product.
  10.  *
  11.  *)
  12.  
  13. (*
  14.  * MiniCrt - simplified version of Borland's CRT unit.
  15.  * Does not EVER do direct video.  The standard crt unit
  16.  * locks up multi-taskers with its direct video checking before
  17.  * the user program can turn it off.
  18.  *
  19.  * (3-1-89)
  20.  *
  21.  *)
  22.  
  23. {$i prodef.inc}
  24.  
  25. unit MiniCrt;
  26.  
  27. interface
  28.  
  29.    uses
  30.       Dos;
  31.  
  32.    var
  33.       stdout:  text;  {output through dos for ANSI compatibility}
  34.  
  35.    function KeyPressed: Boolean;
  36.    function ReadKey: Char;
  37.  
  38.    procedure Window(X1,Y1,X2,Y2: Byte);  {only partial support}
  39.    procedure SetScrollPoint(Y2: Byte);
  40.    procedure FullScreen;
  41.  
  42.    procedure GotoXY(X,Y: Byte);
  43.    function WhereX: Byte;
  44.    function WhereY: Byte;
  45.  
  46.    procedure ClrScr;
  47.    procedure ClrEol;
  48.  
  49.    procedure NormalVideo;
  50.    procedure LowVideo;
  51.    procedure ReverseVideo;
  52.    procedure BlinkVideo;
  53.  
  54.    procedure push_bp; inline($55);
  55.    procedure pop_bp; inline($5D);
  56.  
  57.  
  58.    (* -------------------------------------------------------- *)
  59.    procedure ScrollUp;
  60.    {$F+} function ConFlush(var F: TextRec): integer; {$F-}
  61.    {$F+} function ConOutput(var F: TextRec): integer; {$F-}
  62.    {$F+} function ConOpen(var F: TextRec): Integer; {$F-}
  63.  
  64.  
  65. (* -------------------------------------------------------- *)
  66. implementation
  67.  
  68.    const
  69.       window_y1  : byte = 1;
  70.       window_y2  : byte = 25;
  71.       TextAttr   : byte = $07;
  72.       key_pending: char = #0;
  73.  
  74.  
  75.    procedure intr10(var reg: registers);
  76.    begin
  77.       push_bp;
  78.       intr($10,reg);
  79.       pop_bp;
  80.    end;
  81.  
  82.  
  83.    (* -------------------------------------------------------- *)
  84.    function ReadKey: Char;
  85.    var
  86.       reg: registers;
  87.    begin
  88.       if key_pending <> #0 then
  89.       begin
  90.          ReadKey := key_pending;
  91.          key_pending := #0;
  92.          exit;
  93.       end;
  94.  
  95.       reg.ax := $0000;   {wait for character}
  96.       intr($16,reg);
  97.       if reg.al = 0 then
  98.          key_pending := chr(reg.ah);
  99.  
  100.       ReadKey := chr(reg.al);
  101.    end;
  102.  
  103.  
  104.    (* -------------------------------------------------------- *)
  105.    function KeyPressed: Boolean;
  106.    var
  107.       reg: registers;
  108.    begin
  109.       reg.ax := $0100;   {check for character}
  110.       intr($16,reg);
  111.       KeyPressed := ((reg.flags and FZero) = 0) or (key_pending <> #0);
  112.    end;
  113.  
  114.  
  115.    (* -------------------------------------------------------- *)
  116.    procedure Window(X1,Y1,X2,Y2: Byte);
  117.    begin
  118.       window_y1 := y1;
  119.       window_y2 := y2;
  120.    end;
  121.  
  122.    procedure FullScreen;
  123.    begin
  124.       window_y1 := 1;
  125.       window_y2 := 25;
  126.    end;
  127.  
  128.    procedure SetScrollPoint(Y2: Byte);
  129.    begin
  130.       window_y1 := 1;
  131.       window_y2 := Y2;
  132.    end;
  133.  
  134.  
  135.    (* -------------------------------------------------------- *)
  136.    procedure GotoXY(X,Y: Byte);
  137.    var
  138.       reg: registers;
  139.    begin
  140.       reg.ah := 2;   {set cursor position}
  141.       reg.bh := 0;   {page}
  142.       reg.dh := y-1;
  143.       reg.dl := x-1;
  144.       intr10(reg);
  145.    end;
  146.  
  147.  
  148.    (* -------------------------------------------------------- *)
  149.    function WhereX: Byte;
  150.    var
  151.       reg: registers;
  152.    begin
  153.       reg.ah := 3;
  154.       reg.bh := 0;
  155.       intr10(reg);
  156.       WhereX := reg.dl+1;
  157.    end;
  158.  
  159.    function WhereY: Byte;
  160.    var
  161.       reg: registers;
  162.    begin
  163.       reg.ah := 3;
  164.       reg.bh := 0;
  165.       intr10(reg);
  166.       WhereY := reg.dh+1;
  167.    end;
  168.  
  169.  
  170.    (* -------------------------------------------------------- *)
  171.    procedure ClrScr;
  172.    var
  173.       reg: registers;
  174.    begin
  175.       reg.ax := $0600;  {scroll up, blank window}
  176.       reg.cx := 0;      {upper left}
  177.       reg.dx := $194F;  {line 24, col 79}
  178.       reg.bh := TextAttr;
  179.       intr10(reg);
  180.       GotoXY(1,1);
  181.    end;
  182.  
  183.  
  184.    (* -------------------------------------------------------- *)
  185.    procedure ClrEol;
  186.    var
  187.       reg: registers;
  188.    begin
  189.       reg.ax := $0600;  {scroll up, blank window}
  190.       reg.ch := wherey-1;
  191.       reg.cl := wherex-1;
  192.       reg.dh := reg.ch;
  193.       reg.dl := 79; {lower column}
  194.       reg.bh := TextAttr;
  195.       intr10(reg);
  196.    end;
  197.  
  198.  
  199.    (* -------------------------------------------------------- *)
  200.    procedure NormalVideo;
  201.    begin
  202.       TextAttr := $0F;
  203.    end;
  204.  
  205.    procedure LowVideo;
  206.    begin
  207.       TextAttr := $07;
  208.    end;
  209.  
  210.    procedure ReverseVideo;
  211.    begin
  212.       TextAttr := $70;
  213.    end;
  214.  
  215.    procedure BlinkVideo;
  216.    begin
  217.       TextAttr := $F0;
  218.    end;
  219.  
  220.  
  221.    (* -------------------------------------------------------- *)
  222.    procedure ScrollUp;
  223.    var
  224.       reg: registers;
  225.    begin
  226.       reg.ah := 6;            {scroll up}
  227.       reg.al := 1;            {lines}
  228.       reg.cx := 0;            {upper left}
  229.       reg.dh := window_y2-1;  {lower line}
  230.       reg.dl := 79;           {lower column}
  231.       reg.bh := TextAttr;
  232.       intr10(reg);
  233.    end;
  234.  
  235.  
  236.    (* -------------------------------------------------------- *)
  237.    {$F+} function ConFlush(var F: TextRec): integer; {$F-}
  238.    var
  239.       P:   Word;
  240.       reg: registers;
  241.       x,y: byte;
  242.  
  243.    begin
  244.       {get present cursor position}
  245.       reg.ah := 3;
  246.       reg.bh := 0;
  247.       intr10(reg);
  248.       y := reg.dh+1;
  249.       x := reg.dl+1;
  250.  
  251.       {process each character in the buffer}
  252.       P := 0;
  253.       while P < F.BufPos do
  254.       begin
  255.          reg.al := ord(F.BufPtr^[P]);
  256.  
  257.          case reg.al of
  258.              7:  {$i-} write(stdout,chr(reg.al)); {$i+}
  259.  
  260.              8:  if x > 1 then               {backspace}
  261.                     dec(x);
  262.  
  263.              9:  x := (x+8) and $F8;         {tab}
  264.  
  265.             10:  if y {>}= window_y2 then    {scroll when needed}
  266.                     ScrollUp
  267.                  else
  268.                     inc(y);
  269.  
  270.             13:  x := 1;                     {c/r}
  271.  
  272.             else 
  273.             begin
  274.                  reg.ah := 9;  {display character with TextAttr}
  275.                  reg.bx := 0;  {... does not move the cursor}
  276.                  reg.cx := 1;
  277.                  reg.bl := TextAttr;
  278.                  intr10(reg);
  279.  
  280.                  if x = 80 then   {line wrap?}
  281.                  begin
  282.                     x := 1;
  283.                     if y >= window_y2 then   {scroll during wrap?}
  284.                        ScrollUp
  285.                     else
  286.                        inc(y);
  287.                  end
  288.                  else
  289.                     inc(x);
  290.             end;
  291.          end;
  292.  
  293.          {position physical cursor}
  294.          reg.ah := 2;   {set cursor position}
  295.          reg.bh := 0;   {page}
  296.          reg.dh := y-1;
  297.          reg.dl := x-1;
  298.          intr10(reg);
  299.  
  300.          inc(P);
  301.       end;
  302.  
  303.       F.BufPos:=0;
  304.       ConFlush := 0;
  305.    end;
  306.  
  307.  
  308.    {$F+} function ConOutput(var F: TextRec): integer; {$F-}
  309.    begin
  310.       ConOutput := ConFlush(F);
  311.    end;
  312.  
  313.  
  314.    {$F+} function ConOpen(var F: TextRec): Integer; {$F-}
  315.    begin
  316.       F.InOutFunc := @ConOutput;
  317.       F.FlushFunc := @ConFlush;
  318.       F.CloseFunc := @ConFlush;
  319.       F.BufPos := 0;
  320.       ConOpen := 0;
  321.    end;
  322.  
  323.  
  324.    (* -------------------------------------------------------- *)
  325. var
  326.    e: integer;
  327.    
  328. begin
  329.    with TextRec(output) do
  330.    begin
  331.       BufPos := 0;
  332.       InOutFunc := @ConOutput;
  333.       FlushFunc := @ConFlush;
  334.       OpenFunc  := @ConOpen;
  335.    end;
  336.  
  337.    {$i-}
  338.    assign(stdout,'');
  339.    rewrite(stdout);
  340.    {$i+}
  341. end.
  342.  
  343.